//
//  ContactsTableViewCell.m
//  NuwaRobot
//
//  Created by Kendama on 2017/12/8.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "ContactsTableViewCell.h"
#import "FriendModel.h"

@implementation ContactsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setFriendWithModel:(FriendModel *)model
{
    self.nameLabel.text = model.nickname;
//    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:imageWithName(@"icon_head")];
    if ([model.nickname isEqualToString:@""])
    {
        self.nameLabel.text = @"我的机器人";
        self.iconImageView.image = imageWithName(@"robot_head");
    }
    
    if ([model.count isEqualToString:@"1"])
    {
        self.countLabel.hidden = NO;
    }
    else
    {
        self.countLabel.hidden = YES;
    }
}

- (UIImageView *)iconImageView
{
    if(!_iconImageView)
    {
        UIView *superView = self.contentView;
        _iconImageView = [[UIImageView alloc]init];
        [superView addSubview:_iconImageView];
        _iconImageView.layer.cornerRadius = px1920Height(140)/2;
        _iconImageView.layer.masksToBounds = YES;
    }
    return _iconImageView;
}
- (UILabel *)nameLabel
{
    if(!_nameLabel)
    {
        UIView *superView = self.contentView;
        _nameLabel = [[UILabel alloc]init];
        [superView addSubview:_nameLabel];
        [_nameLabel setFont:fontCommonSize];
        [_nameLabel setTextColor:[UIColor whiteColor]];
    }
    return _nameLabel;
}

- (UILabel *)countLabel
{
    if(!_countLabel)
    {
        UIView *superView = self.contentView;
        _countLabel = [[UILabel alloc]init];
        [superView addSubview:_countLabel];
        [_countLabel setFont:fontWithSize(13)];
        [_countLabel setTextColor:[UIColor whiteColor]];
        _countLabel.backgroundColor = [UIColor redColor];
        _countLabel.layer.cornerRadius = px1920Height(30)/2;
        _countLabel.layer.masksToBounds = YES;
        _countLabel.textAlignment = NSTextAlignmentCenter;
        _countLabel.text = @"";
    }
    return _countLabel;
}



- (void)masLayoutSubview
{
    __weak UIView *superView = self.contentView;
    UIView *bgView = [[UIView alloc] init];
    [superView addSubview:bgView];
    bgView.backgroundColor = rgba(27,44,81,1);
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(superView);
        make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(10));
        make.bottom.mas_equalTo(superView.mas_bottom).with.offset(-px1920Height(10));
    }];
    bgView.layer.cornerRadius = 3;
    
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(35));
        make.height.width.mas_equalTo(px1920Height(140));
    }];
    
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.left.mas_equalTo(_iconImageView.mas_right).with.offset(px1080Width(68));
        make.right.mas_equalTo(superView.mas_right);
    }];
    
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_iconImageView.mas_top);
        make.right.mas_equalTo(_iconImageView.mas_right);
        make.height.width.mas_equalTo(px1920Height(30));
    }];
    
    self.countLabel.hidden = YES;
}

@end
